package permission

import (
	"x-admin/backend/internal/middleware"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// RegisterRoutes 注册权限管理路由
func RegisterRoutes(r *gin.RouterGroup, db *gorm.DB) {
	// 创建依赖
	repo := NewRepository(db)
	service := NewService(repo)
	handler := NewHandler(service)

	// 创建权限路由组
	permissionGroup := middleware.NewPermissionGroup(r.Group("/permissions"), db)
	{
		permissionGroup.GET("", "permission:list", handler.List)                  // 获取权限列表
		permissionGroup.GET("/tree", "permission:tree", handler.GetTree)          // 获取权限树
		permissionGroup.GET("/all", "permission:list", handler.GetAllPermissions) // 获取所有权限
		permissionGroup.GET("/:id", "permission:view", handler.GetByID)           // 获取权限详情
		permissionGroup.POST("", "permission:create", handler.Create)             // 创建权限
		permissionGroup.PUT("/:id", "permission:update", handler.Update)          // 更新权限
		permissionGroup.DELETE("/:id", "permission:delete", handler.Delete)       // 删除权限
	}
}
